package 优先算法.二分查找.山脉数组的峰顶索引;

/**
 * https://leetcode.cn/problems/peak-index-in-a-mountain-array/description/
 */

public class Main {
    public static void main(String[] args) {
        Solution so = new Solution();
        int[] arr = {0,10,5,2};
        int rel = so.peakIndexInMountainArray(arr);
        System.out.println(rel);
    }
}
class Solution {
    public int peakIndexInMountainArray(int[] nums) {
        int left = 0,right = nums.length-1;
        while(left < right){
            int mid = left + (right - left + 1)/2;
            if(nums[mid] >= nums[mid - 1]){
                left = mid;
            }
            if(nums[mid] < nums[mid - 1]){
                right = mid - 1;
            }
        }
        return left;
    }
}